var back=document.querySelector('#back');
back.onclick=function(e){
    window.history.back(-1); 
    e.prevent();
}


var regForm = document.querySelector(".reg-form");
// console.log(regForm);

var errorTips = {
    dl: {
        valueMissing: "输入不能为空！",
        typeMismatch: "请输入一个符合规格昵称-(用户名/手机号码/邮箱！)",
        patternMismatch: "请输入一个符合规格昵称-(用户名/手机号码/邮箱！)"
    },
    psw: {
        valueMissing: "请输入您的账号密码！",
        typeMismatch: "请输入一个长度为6 - 16 位的密码！",
        patternMismatch: "请输入一个长度为6 - 16 位的密码！"
    }
}

regForm.addEventListener("invalid", function (e) {
    console.log('表单验证失败');
    var element = e.target;
    console.log(element);
    var validityState = element.validity;//获取表单元素的验证状态
    var eleName = element.name;//获取元素的name属性
    console.log(eleName, validityState);
    if (validityState.valueMissing) {
        element.setCustomValidity(errorTips[eleName].valueMissing);
    } else if (validityState.typeMismatch) {
        element.setCustomValidity(errorTips[eleName].typeMismatch);
    } else if (validityState.patternMismatch) {
        element.setCustomValidity(errorTips[eleName].patternMismatch);
    } else { element.setCustomValidity(""); }

}, true);